package com.study.rabbitmq2.topics;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import com.study.rabbitmq2.util.ConnectionUtil;

/**
 * @Author chenyeqing
 * @Date 2021/11/24 22:01
 */
public class Send {
    private final static String EXCHANGE_NAME = "test_topic_exchange";

    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();

        Channel channel = connection.createChannel();

        // 声明exchange 指定类型为 topic
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC, true);

        String msg = "这是一只行动迅速的橙色兔子";

        channel.basicPublish(EXCHANGE_NAME, "lazy.brown.fox", MessageProperties.PERSISTENT_TEXT_PLAIN, msg.getBytes());
        System.out.println("[动物描述] Sent：" + msg);
        channel.close();
        connection.close();
    }
}
